# This Python file uses the following encoding: utf-8
from django.db import models
from django.template.defaultfilters import slugify

class Familia(models.Model):
    nom = models.CharField(u"Nom", max_length=250, help_text = u'''Nom de la família''', blank = False ) 
    logo = models.ImageField(u"Logo", blank=True, null=True, upload_to="families", help_text = u"Logo de la família"  )
    slug = models.SlugField()
    
    def save(self, *args, **kwargs):
        self.slug = self.slug if self.slug else slugify(self.nom)
        super(Familia, self).save(*args, **kwargs)
    

class Cicle(models.Model):
    GRAU_CHOICES = (
            ('M',u'Mitjà'),
            ('S',u'Superior'),
                    ) 
    
    familia = models.ForeignKey(Familia)
    codi = models.CharField(u"Acrònim", max_length=20, help_text = u'''Acrònim del cicle''', blank = False ) 
    nom = models.CharField(u"Nom", max_length=250, help_text = u'''Nom del cicle''', blank = False ) 
    nivell = models.CharField(u"Nivell", max_length=1, choices=GRAU_CHOICES, help_text = u'''Nivel del cicle''', blank = False )
    logo = models.ImageField(u"Logo", blank=True, null=True, upload_to="cicles", help_text = u"Logo del cicle"  )
    slug = models.SlugField()
    
    def save(self, *args, **kwargs):
        self.slug = self.slug if self.slug else slugify(self.nom)
        super(Cicle, self).save(*args, **kwargs)

    class Meta:
        ordering=['familia','nivell', 'nom']
        db_table = u'cicles'
        verbose_name = u'Cicle Formatiu'
        verbose_name_plural = u'Cicles Formatius'
        
    def __unicode__(self):
        return u"{0} - {1}".format( self.codi, self.nom )
    
class CiclePY_codi(Cicle):    
    class Meta:
        proxy = True
        ordering=['familia','nivell', 'codi']

    def __unicode__(self):
        return unicode( self.Cicle )
    
    
